let { HttpRequest, globalData, mfutil, UserAccess, URLChangeCommon ,addUserStat } = getApp();
const app = getApp();
Page({
  data: {
    a: false,
    id: null,
    detailData: {
      is_come_out: 0,    //0：未开奖 1：已开奖
      islucky: null,    //是否中奖
    },
    winActive: false,   //中奖列表弹窗状态
    islucky: null,
    router: '/pages/equity-detail2/equity-detail2',
    pagetitle: '权益中心抽奖结果页',
    loadingActive: false
  },
  onLoad(options) {
    my.hideShareMenu({
      success() {
      },
      fail() {
      },
    });
    console.log(options, 'optionsoptionsoptionsoptionsoptionsoptions')
    let islucky = JSON.parse(options.islucky)
    this.setData({
      id: options.id,
      islucky,
      method: options.method
    })
    console.log(this.data, '======================================')
    this.initPage()
    /**
* 用户行为记录埋点
*/
    let channel = app.globalData.channel;
    let routerArr = getCurrentPages();
    let UserAccessoptions = {
      grade: routerArr.length > 1 ? routerArr[routerArr.length - 2].data.router : '',
      name: routerArr[routerArr.length - 1].data.pagetitle,
      address: options.id,
    }
    let track = UserAccess(UserAccessoptions)
  },
  //页面初始化
  async initPage() {
    let { detailData, id } = this.data;
    let path = `/vans-family/api/v2.1/project/vansFamily/cms/forward/get?url=/v2/cms/api/tile/${id}`;
    let parmasObj = {
      member_id_type: 1,
      member_id: globalData.userInfo.memberId
    }
    this.setData({
      loadingActive: true
    })
    let res = await HttpRequest(path, 'POST', parmasObj, {});
    if (res.data.code == 0) {
      this.setData({
        detailData: res.data.data,
        json: JSON.stringify(res.data.data.tile_info),
        type: res.data.data.tile_info.type,
        islucky: res.data.data.tile_info.is_lucky,
        tileid: res.data.data.tile_info.id
      })
    }
    console.log(this.data.detailData);
    
    this.setData({
      loadingActive: false
    })
  },
  // winChange() {
  //   let { winActive } = this.data;
  //   this.setData({
  //     winActive: !winActive
  //   })
  // },
  shareFn() {
    my.showSharePanel();
  },
  wangwang() {
    my.tb.openMessage({
      sellerNick: "商家测试账号",
      success: (res) => {
      },
      fail: (res) => {
      },
    })
  },
  navigateBack() {
    let { method } = this.data;
    if (method == 'member') {
      my.switchTab({
        url: '/pages/member-privilege-page/member-privilege-page',
        success() {
          let options = {
            currentTarget: {
              dataset: {
                index: 0
              }
            }
          }
          mfutil.tempConfig._refs.selectCard && mfutil.tempConfig._refs.selectCard.navSelect(options)
        }
      });
    } else {
      my.switchTab({
        url: '/pages/equity-page/equity-page',
        success() {
          let options = {
            currentTarget: {
              dataset: {
                index: 0
              }
            }
          }
          mfutil.tempConfig._refs.selectCard && mfutil.tempConfig._refs.selectCard.navSelect(options)
        }
      });
    }
  },
  winChange() {
    this.setData({
      winActive: false
    })
  },
  urlChange(event) {
    let { item } = event.currentTarget.dataset;
    URLChangeCommon(item)
    /**
* 用户行为记录埋点
*/
    let routerArr = getCurrentPages();
    let params = app.globalData.params;
    let channel = app.globalData.channel;
    let UserAccessoptions = {
      grade: routerArr.length > 1 ? routerArr[routerArr.length - 2].data.router : '',
      name: routerArr[routerArr.length - 1].data.pagetitle,
      address: this.data.detailData.tile_info.id,
      String4: item.cta_button_name

    }
    let track = UserAccess(UserAccessoptions)

     // 自定义埋点
    let customAccessoptions = {
      customType: 'TileCTA_'+this.data.detailData.tile_info.id+'_'+item.cta_button_name
    }

    let tracks = addUserStat(customAccessoptions)
  },
});
